"use client";

import { type PlateElementProps } from "platejs/react";

import { type VariantProps, cva } from "class-variance-authority";
import { PlateElement } from "platejs/react";

const headingVariants = cva("relative mb-1", {
  variants: {
    variant: {
      h1: "mt-[1.6em] pb-1 font-heading text-4xl font-bold",
      h2: "mt-[1.4em] pb-px font-heading text-2xl font-semibold tracking-tight",
      h3: "mt-[1em] pb-px font-heading text-xl font-semibold tracking-tight",
      h4: "mt-[0.75em] font-heading text-lg font-semibold tracking-tight",
      h5: "mt-[0.75em] text-lg font-semibold tracking-tight",
      h6: "mt-[0.75em] text-base font-semibold tracking-tight",
    },
  },
});

export function HeadingElement({
  variant = "h1",
  ...props
}: PlateElementProps & VariantProps&lt;typeof headingVariants&gt;) {
  return (
    &lt;PlateElement
      as={variant!}
      className={headingVariants({ variant })}
      {...props}
    &gt;
      {props.children}
    &lt;/PlateElement&gt;
  );
}

export function H1Element(props: PlateElementProps) {
  return &lt;HeadingElement variant="h1" {...props} /&gt;;
}

export function H2Element(props: PlateElementProps) {
  return &lt;HeadingElement variant="h2" {...props} /&gt;;
}

export function H3Element(props: PlateElementProps) {
  return &lt;HeadingElement variant="h3" {...props} /&gt;;
}

export function H4Element(props: PlateElementProps) {
  return &lt;HeadingElement variant="h4" {...props} /&gt;;
}

export function H5Element(props: PlateElementProps) {
  return &lt;HeadingElement variant="h5" {...props} /&gt;;
}

export function H6Element(props: PlateElementProps) {
  return &lt;HeadingElement variant="h6" {...props} /&gt;;
}
